function add0(m) { return m < 10 ? '0' + m : m };
function format(shijianchuo) {
  //shijianchuo是整数，否则要parseInt转换
  var time = new Date(parseInt(shijianchuo));
  var y = time.getFullYear();
  var m = time.getMonth() + 1;
  var d = time.getDate();
  var h = time.getHours();
  var mm = time.getMinutes();
  var s = time.getSeconds();
  return y + '-' + this.add0(m) + '-' + this.add0(d)+ ' ' + this.add0(h) + ':' + this.add0(mm) + ':' + this.add0(s);
};
function bijiao(hisTime, nowTime) {
  if (!arguments.length) return '';
  let arg = arguments,
    now = arg[1] ? arg[1] : new Date().getTime(),
    diffValue = now - arg[0],
    result = '',

    minute = 1000 * 60,
    hour = minute * 60,
    day = hour * 24,
    halfamonth = day * 15,
    month = day * 30,
    year = month * 12,

    _year = diffValue / year,
    _month = diffValue / month,
    _week = diffValue / (7 * day),
    _day = diffValue / day,
    _hour = diffValue / hour,
    _min = diffValue / minute,
    _miao = diffValue / 1000;

  if (_year >= 1) result = this.format(hisTime);
  else if (_month >= 1) result = this.format(hisTime);
  else if (_week >= 1) result = this.format(hisTime);
  else if (_day >= 1) result = this.format(hisTime);
  else if (_hour >= 1) result = parseInt(_hour) + "小时前";
  else if (_min >= 1) result = parseInt(_min) + "分钟前";
  else if (_miao >= 5) result = parseInt(_miao) + "秒前";
  else result = "刚刚";
  return result;
};
module.exports = {
  add0: add0,
  format: format,
  bijiao: bijiao

}